package com.example.alee.mybatis.springmybatis.mapper;

import com.example.alee.mybatis.springmybatis.po.ArticlePo;
import org.apache.ibatis.annotations.*;

public interface ArticleMapper {

    //select 按照主键查询
    @Select("""
            select id,user_id,title,summary,read_count,create_time,update_time
            from article where id = #{ArticleID}
            """)
    // 查询结果集和PO映射  列和PO结果映射
    @Results(id = "BaseArticleMap", value = {
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "user_id", property = "user_id"),
            @Result(column = "title", property = "title"),
            @Result(column = "summary", property = "summary"),
            @Result(column = "read_count", property = "read_count"),
            @Result(column = "create_time", property = "create_time"),
            @Result(column = "update_time", property = "update_time"),
    })
    ArticlePo selectById(@Param("ArticleID") Integer id);


    //install
    @Insert("""
             INSERT INTO article (user_id, title, summary, read_count, create_time, update_time) 
             VALUES 
             (#{user_id},#{title},#{summary},#{read_count},#{create_time},#{update_time})
            """)
    int insertArticle(ArticlePo articlePo);


    @Update("""
            UPDATE article set read_count = #{readCount} WHERE id = #{id}
            """)
    int updateArticle(int id, int readCount);


    @Delete("""
            DELETE from  article where  id = #{id}
            """)
    int deleteArticle(int id);
}
